﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Queries;
using Castle.Components.Validator;
using System.ComponentModel;

namespace Mang24k99.Model.GOLD
{
    [ActiveRecord(Table = "KT_GOLD_SALEPRICE")]
    public partial class MKtGoldSaleprice : ActiveRecordBase
    {
        public static IList<MKtGoldSaleprice> SelectAll()
        {
            return (IList<MKtGoldSaleprice>)FindAll(typeof(MKtGoldSaleprice));
        }
        public static MKtGoldSaleprice SelectByPrimaryKey(object ID)
        {
            return (MKtGoldSaleprice)FindByPrimaryKey(typeof(MKtGoldSaleprice), ID);
        }
        public static IList<MKtGoldSaleprice> SelectALLByProperty(string property, object value)
        {
            return (IList<MKtGoldSaleprice>)FindAllByProperty(typeof(MKtGoldSaleprice), property, value);
        }
        public static IList<MKtGoldSaleprice> SelectALLSliced(int firstResult, int maxResult, NHibernate.Expression.DetachedCriteria criteria)
        {

            return (IList<MKtGoldSaleprice>)SlicedFindAll(typeof(MKtGoldSaleprice), firstResult, maxResult, criteria);
        }
        protected override void OnDelete()
        {
            MKtGoldSalepriceHistory mHistory = new MKtGoldSalepriceHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.DeleteTime = DateTime.Now;
            mHistory.Create();
            base.OnDelete();
        }
        /// <summary>
        /// 当编辑时往历史表插入一条记录
        /// </summary>
        /// <param name="saleprice"></param>
        public static void  OnEditToHistory(MKtGoldSaleprice saleprice )
        {
            MKtGoldSalepriceHistory mHistory = new MKtGoldSalepriceHistory();
            Common.ModelCommon.CopyObjectValues(saleprice,mHistory);
            mHistory.ModifyTime = DateTime.Now;
            try
            {
                mHistory.Create();
            }
            catch (System.Exception e)
            {
            	
            }
            
        }
        /// <summary>
        /// 通过where语句查询记录
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static IList<MKtGoldSaleprice> SelectBywhere(string where)
        {
            string hql = @"from MKtGoldSaleprice saleprice " + where;
            SimpleQuery query = new SimpleQuery(typeof(MKtGoldSaleprice), hql);
            return (IList<MKtGoldSaleprice>)ExecuteQuery(query);
        }

        /// <summary>
        /// 一对一关系
        /// </summary>
        [OneToOne]
        public MKtGoldProduct MKtGoldProduct
        {
            get
            {
                if (_MKtGoldProduct == null)
                {
                    _MKtGoldProduct = new MKtGoldProduct();
                }
                return _MKtGoldProduct;
            }
            set
            {
                _MKtGoldProduct = value;
            }
        }
        /// <summary>
        /// Gets or sets the ProcductNO.()
        /// </summary>
        /// <value>The ProcductNO.</value>
        [PrimaryKey(PrimaryKeyType.Foreign, "PROCDUCT_NO")]
        public int ProcductNO
        {
            get
            {
                return _ProcductNO;
            }
            set
            {
                _ProcductNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the ID.()
        /// </summary>
        /// <value>The ID.</value>
        [Property("ID", Insert = false, Update = false)]
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }


        /// <summary>
        /// Gets or sets the BuyPrice.()
        /// </summary>
        /// <value>The BuyPrice.</value>
        [Property("BUY_PRICE")]
        public decimal BuyPrice
        {
            get
            {
                return _BuyPrice;
            }
            set
            {
                _BuyPrice = value;
            }
        }


        /// <summary>
        /// Gets or sets the SalePrice.()
        /// </summary>
        /// <value>The SalePrice.</value>
        [Property("SALE_PRICE")]
        public decimal SalePrice
        {
            get
            {
                return _SalePrice;
            }
            set
            {
                _SalePrice = value;
            }
        }


        /// <summary>
        /// Gets or sets the ChargeFee.()
        /// </summary>
        /// <value>The ChargeFee.</value>
        [Property("CHARGE_FEE")]
        public string  ChargeFee
        {
            get
            {
                return _ChargeFee;
            }
            set
            {
                _ChargeFee = value;
            }
        }


        /// <summary>
        /// Gets or sets the TotalPrice.()
        /// </summary>
        /// <value>The TotalPrice.</value>
        [Property("TOTAL_PRICE")]
        public decimal TotalPrice
        {
            get
            {
                return _TotalPrice;
            }
            set
            {
                _TotalPrice = value;
            }
        }


        /// <summary>
        /// Gets or sets the UpdateTime.()
        /// </summary>
        /// <value>The UpdateTime.</value>
        [Property("UPDATE_TIME")]
        public DateTime? UpdateTime
        {
            get
            {
                return _UpdateTime;
            }
            set
            {
                _UpdateTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the IsValidate.()
        /// </summary>
        /// <value>The IsValidate.</value>
        [Property("IS_VALIDATE")]
        public int? IsValidate
        {
            get
            {
                return _IsValidate;
            }
            set
            {
                _IsValidate = value;
            }
        }


        /// <summary>
        /// Gets or sets the InputTime.()
        /// </summary>
        /// <value>The InputTime.</value>
        [Property("INPUT_TIME")]
        public DateTime? InputTime
        {
            get
            {
                return _InputTime;
            }
            set
            {
                _InputTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the ModifyTime.()
        /// </summary>
        /// <value>The ModifyTime.</value>
        [Property("MODIFY_TIME")]
        public DateTime? ModifyTime
        {
            get
            {
                return _ModifyTime;
            }
            set
            {
                _ModifyTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the DeleteTime.()
        /// </summary>
        /// <value>The DeleteTime.</value>
        [Property("DELETE_TIME")]
        public DateTime? DeleteTime
        {
            get
            {
                return _DeleteTime;
            }
            set
            {
                _DeleteTime = value;
            }
        }

        /// <summary>
        /// Gets or sets the PriceDatetime.(PriceDatetime)
        /// </summary>
        /// <value>The PriceDatetime.</value>
        /// <remarks>
        /// PriceDatetime
        /// </remarks>
        [Property("PRICE_DATETIME"),
        ]
        public DateTime? PriceDatetime
        {
            get
            {
                return _PriceDatetime;
            }
            set
            {
                _PriceDatetime = value;
            }
        }


        /// <summary>
        /// Gets or sets the PriceChange.(PriceChange)
        /// </summary>
        /// <value>The PriceChange.</value>
        /// <remarks>
        /// PriceChange
        /// </remarks>
        [Property("PRICE_CHANGE"),
        ]
        public decimal PriceChange
        {
            get
            {
                return _PriceChange;
            }
            set
            {
                _PriceChange = value;
            }
        }


        /// <summary>
        /// Gets or sets the LastbuyPrice.(LastbuyPrice)
        /// </summary>
        /// <value>The LastbuyPrice.</value>
        /// <remarks>
        /// LastbuyPrice
        /// </remarks>
        [Property("LASTBUY_PRICE"),
        ]
        public decimal LastbuyPrice
        {
            get
            {
                return _LastbuyPrice;
            }
            set
            {
                _LastbuyPrice = value;
            }
        }


        /// <summary>
        /// Gets or sets the LastsalePrice.(LastsalePrice)
        /// </summary>
        /// <value>The LastsalePrice.</value>
        /// <remarks>
        /// LastsalePrice
        /// </remarks>
        [Property("LASTSALE_PRICE"),
        ]
        public decimal LastsalePrice
        {
            get
            {
                return _LastsalePrice;
            }
            set
            {
                _LastsalePrice = value;
            }
        }


        /// <summary>
        /// Gets or sets the IsLastprice.(IsLastprice)
        /// </summary>
        /// <value>The IsLastprice.</value>
        /// <remarks>
        /// IsLastprice
        /// </remarks>
        [Property("IS_LASTPRICE"),
        ValidateRange(0, 2147483647, "IsLastprice的值要在0到2147483647之间"),
        ]
        public int? IsLastprice
        {
            get
            {
                return _IsLastprice;
            }
            set
            {
                _IsLastprice = value;
            }
        }
        

        private int _ProcductNO;
        private int _ID;
        private decimal _BuyPrice;
        private decimal _SalePrice;
        private MKtGoldProduct _MKtGoldProduct;

        private string  _ChargeFee;

        private decimal _TotalPrice;

        private DateTime? _UpdateTime;

        private int? _IsValidate;

        private DateTime? _InputTime;

        private DateTime? _ModifyTime;

        private DateTime? _DeleteTime;
        private DateTime? _PriceDatetime;

        private decimal _PriceChange;

        private decimal _LastbuyPrice;

        private decimal _LastsalePrice;

        private int? _IsLastprice;


        public static void OnEditToHistory(MKtGoldProduct mKtGoldProduct)
        {
            throw new NotImplementedException();
        }
    }
}
